﻿using System;
using SchemaGen.Xsd;

namespace SchemaGen.Attributes
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class XmlStringTypeAttribute : XmlSimpleTypeAttribute
    {
        public string Pattern { get; private set; }

        public SSimpleType _Restriction;
        public override SSimpleType Restriction
        {
            get
            {
                if (_Restriction == null)
                {
                    _Restriction = SSimpleType.GetPatternRestriction(Pattern);
                    _Restriction.Name = Name;
                    _Restriction.Documentation = Documentation;
                }

                return _Restriction;
            }
        }

        public XmlStringTypeAttribute(string name, string pattern)
            : base(name)
        {
            Pattern = pattern;
        }
    }
}
